package com.qingyun.form.internal

import android.content.Context
import androidx.recyclerview.widget.LinearSmoothScroller
import androidx.recyclerview.widget.RecyclerView

class TopLinearSmoothScroller(context: Context) : LinearSmoothScroller(context) {
    /** 是否开启动画 */
    var enableAnim = true
    private val anim by lazy { FormBackgroundAnimation() }

    override fun getVerticalSnapPreference(): Int {
        return SNAP_TO_ANY
    }

    fun scrollNow(recyclerView: RecyclerView, position: Int) {
        this.targetPosition = position
        recyclerView.layoutManager?.startSmoothScroll(this)
    }

    override fun onStop() {
        super.onStop()
        if (enableAnim) {
            this.findViewByPosition(targetPosition)?.let {
                anim.start(it)
            }
        }
    }
}